package com.strato.rpc.api.v1_0_0;

import org.osgi.framework.BundleContext;

import com.strato.base.env.v1_0_0.GlobalEnvironment;
import com.strato.base.osgi.v1_0_0.BundleUtil;
import com.strato.rpc.api.v1_0_0.activator.Activator;

public interface Transport {

	public static final String AUTO_DETECT="(AUTO)";

	/**
	 * if AUTO_DETECT,try ${strato.rpc.Transport} from GlobalEnvironment,then get default from bundleContext
	 * @param id
	 * @return
	 */
	public static Transport get(String id){
		BundleContext context = Activator.getContext();
		if(AUTO_DETECT.equals(id)){
			String configId=GlobalEnvironment.getInstance().get("strato.rpc.transport");
			if(configId!=null){
				return BundleUtil.getService(context, Transport.class, "(id="+configId+")");
			}
			return BundleUtil.getService(context, Transport.class,null);
		}
		return BundleUtil.getService(context, Transport.class, "(id="+id+")");
	}

	public void export(String id, Object object, Class<?> intf, String bundleName);

	public void unexport(String id);

	public Object createProxy(String id, Class<?> intf, int retry);
}
